//
//  LLMyHeaderTableViewCell.m
//  LoveLove
//
//  Created by wkf on 2019/3/28.
//  Copyright © 2019 wkf. All rights reserved.
//

#import "LLMyHeaderTableViewCell.h"
#import "UIImageView+WebCache.h"//图片加载
#import "QWebVC.h"
#import "LLLoginViewController.h"

@implementation LLMyHeaderTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView{
    self.headImage = [[UIImageView alloc] initWithFrame:CGRectMake(LLScreenWidth/2-40, 14, 80, 80)];
    self.headImage.image = [UIImage imageNamed:@"椭圆 1596"];
    self.headImage.layer.masksToBounds = YES;
    self.headImage.contentMode = UIViewContentModeScaleAspectFill;
    self.headImage.layer.cornerRadius = 40;
    [self.contentView addSubview:self.headImage];
    
    self.titleLabel = [LLInitBaseViewTool labelWithText:@"编辑个人资料" textColor:LLColorRGB(138) font:14 textAlignment:NSTextAlignmentCenter];
    self.titleLabel.frame = CGRectMake(15, 113, LLScreenWidth-30, 14);
    [self.contentView addSubview:self.titleLabel];
    
    self.signInButton = [LLInitBaseViewTool buttonWithTitle:@"签到" image:@"arrow_back_left_navigation_previous_128px_1225467_easyicon.net 拷贝 5" titleColor:LLColorRGB(0) font:12];
    self.signInButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    self.signInButton.frame = CGRectMake(LLScreenWidth-117, 69-14, 100, 40);
    CGRect rect = [@"签到" boundingRectWithSize:CGSizeMake(1000, 100) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : LLRegularFont(12)} context:nil];
    self.signInButton.titleEdgeInsets = UIEdgeInsetsMake(0, -self.signInButton.imageView.image.size.width-2.5, 0, self.signInButton.imageView.image.size.width+2.5);
    //button图片的偏移量，这个偏移量是相对于标题的
    self.signInButton.imageEdgeInsets = UIEdgeInsetsMake(0, rect.size.width+2.5, 0, -rect.size.width-2.5);
    [self.signInButton addTarget:self action:@selector(didSelectwithSignIn) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.signInButton];
}

-(void)didSelectwithSignIn{
//    LLSignViewController *vc = [LLSignViewController new];
//    [[UIViewController currentViewController].navigationController pushViewController:vc animated:NO];
    if (![LLUserInfo sharedUser].isLogin) {
        LLLoginViewController *vc = [LLLoginViewController new];
        [[UIViewController currentViewController].navigationController pushViewController:vc animated:YES];
        return;
    }
    QWebVC *vc = [QWebVC new];
    vc.urlString = [NSString stringWithFormat:@"http://www.haoaih.com/h5/users/get_sign_list?u_id=%@&num=%@",[LLUserInfo sharedUser].user_id,[LLUserInfo sharedUser].user_random];
    [[UIViewController currentViewController].navigationController pushViewController:vc animated:YES];

}
/**
 刷新登录界面
 */
-(void)refleshView{
    LLUserInfo *user = [LLUserInfo sharedUser];
    NSURL *ImagePath1 =[NSURL URLWithString: user.user_avatar];
    [self.headImage sd_setImageWithURL:ImagePath1 placeholderImage:[UIImage imageNamed:@"default_user"]];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
